<template>
    <!-- 人员管理下的员工管理里的:员工详情组件 -->
    <div>
        <el-dialog title="员工详情" :visible.sync="dialogFormVisible">
            <el-form ref="form" :model="form">
                <!-- 头像 -->
                <el-form-item
                    style="margin: 0; display: flex;justify-content: center;"
                >
                    <img :src="form.photo_url" alt="头像"
                    style="height: 140px;width: 140px;border-radius: 50%;margin-top: -50px;"
                    >
                </el-form-item>
                <!-- 用户名、性别、年龄、联系电话 -->
                <el-form-item>
                    <span style="margin-right: 15px;">用户名:</span>
                    <el-input v-model="form.username" style="width: 25%;"></el-input>

                    <span style="margin-left: 15px; margin-right: 15px;">性别:</span>
                    <el-input v-model="form.sex" style="width: 10%;" :disabled="true"></el-input>

                    <span style="margin-left: 15px; margin-right: 15px;">年龄:</span>
                    <el-input v-model="form.age" style="width: 10%;"></el-input>

                    
                    <span style="margin-left: 15px; margin-right: 15px;">联系电话:</span>
                    <el-input v-model="form.phone" style="width: 20%;"></el-input>
                </el-form-item>

                <!-- 近期登录时间、地址、身份 -->
                <el-form-item>
                    <span style="margin-right: 15px;">近期登录时间:</span>
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.last_login_time" style="width: 20%;" :disabled="true"></el-date-picker>

                    <span style="margin-left: 15px; margin-right: 15px;">地址:</span>
                    <el-input v-model="form.address" style="width: 38%;"></el-input>

                    
                    <span style="margin-left: 15px; margin-right: 15px;">身份:</span>
                    <el-input v-model="form.status" style="width: 13%;" :disabled="true"></el-input>
                </el-form-item>

                <!-- 所属管理员、负责区域 -->
                <el-form-item>
                    <span style="margin-right: 15px;">所属管理员:</span>
                    <el-select v-model="form.admin_id" placeholder="请选择变更的员工" style="width: 30%;">
                        <el-option :label="item.username" :value="item.id" v-for="item in adminList" :key="item.id"></el-option>
                    </el-select>

                    <span style="margin-left: 15px; margin-right: 15px;">负责区域:</span>
                    <el-input v-model="form.area" style="width: 46.5%;"></el-input>

                </el-form-item>

                <!-- 负责区域、账号建档时间、近期修改时间 -->
                <el-form-item>
                    <span style="margin-right: 15px;">身份编号:</span>
                    <el-input v-model="form.id_card" style="width: 25%;" :disabled="true"></el-input>

                    <span style="margin-left: 15px; margin-right: 15px;">账号建档时间:</span>
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.create_time" style="width: 18%;" :disabled="true"></el-date-picker>
                    
                    <span style="margin-left: 15px; margin-right: 15px;">近期修改时间:</span>
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.update_time" style="width: 18%;" :disabled="true"></el-date-picker>

                </el-form-item>

                <el-divider></el-divider>

                <!-- 员工分数、员工评价 -->
                <div
                    style="margin-bottom: 10px;"
                    >
                        员工得分(满分5分):
                </div>

                <el-rate
                  v-model="form.grade"
                  disabled
                  show-score
                  text-color="#ff9900"
                  score-template="{value}">
                </el-rate>

                <el-form-item label="员工评价:">
                    <el-input type="textarea" v-model="form.appraise"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button 
                        type="primary" 
                        @click="onSubmitUpdate"
                        >
                            修改资料
                    </el-button>
                    <el-button 
                        type="warning"
                        style="margin-left: 3%;"
                        @click="onSubmitTotal"
                        >
                        重置得分(5分)
                    </el-button>
                    <el-button 
                        @click="dialogFormVisible = false"
                        style="margin-left: 60%;"
                        >
                            取消
                    </el-button>
                </el-form-item>

            </el-form>
        </el-dialog>
    </div>
</template>

<script>
    import myAxios from '@/tools/myAxios';
    import Qs from 'qs';
    export default {
        name:'EmployeeDialogBox',
        data() {
            return {
                // 控制对话框是否显示
                dialogFormVisible:false,
                // 存放对话框里的数据
                form: {},
                // 所有管理员信息
                adminList:[]
            }
        },
        methods:{
            // 修改按钮
            onSubmitUpdate() {
                myAxios(
                    'http://localhost:8088/admin/updateemployeeinfo',
                    'post',
                    Qs.stringify(this.form),
                    (data)=>{
                        // 提示一下
                        this.$message({
                            message: '修改信息成功!',
                            type: 'success'
                        });
                        // 刷新页面
                        window.location.reload();
                    }
                )
            },

            // 重置得分
            onSubmitTotal(){
                myAxios(
                    'http://localhost:8088/admin/updateemployeegrade?id='+this.form.id,
                    'get',
                    null,
                    (data)=>{
                        // 将form中的数据临时修改成5分
                        this.form.grade = 5;
                        // 提示一下
                        this.$message({
                            message: '分数重置成功!',
                            type: 'success'
                        });
                        window.location.reload();
                    }
                )
            },

            // 点击员工详情的回调方法
            clickDetailEmployee(data){
                this.form = data;
                this.dialogFormVisible = true;
            }
        },
        mounted(){
            // 绑定自定义事件
            this.$bus.$on('clickDetailEmployee',this.clickDetailEmployee)

            // 获取所有的管理员信息
            myAxios(
                'http://localhost:8088/admin/getalladmin',
                'get',
                null,
                (data)=>{
                    this.adminList = data;
                }
            )
        },
        beforeDestroy(){
            // 解绑
            this.$bus.$off('clickDetailEmployee');
        }
    }
</script>

<style>

</style>